home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / pc / ps40sdk / examples / format / simpleformat / common / simpleformatscripting.c < prev   
Encoding:
C/C++ Source or Header  |  1996-10-22  |  3.7 KB  |  156 lines

  1. /*
  2.     File: SimpleFormatScripting.c
  3.  
  4.     Copyright (c) 1996, Adobe Systems Incorporated.
  5.     All rights reserved.
  6.     
  7.     Scripting functions for SimpleFormat example module.
  8.  
  9. */
  10.  
  11. #include "SimpleFormat.h"
  12.  
  13. /*****************************************************************************/
  14.  
  15. /* Checks the parameters against scripting-returned parameters, if any, and
  16.    updates our parameters to match ones given to us by the scripting system. */
  17.  
  18. Boolean ReadScriptParamsOnRead (GPtr globals)
  19. {
  20.     PIReadDescriptor            token = NULL;
  21.     DescriptorKeyID                key = 0;
  22.     DescriptorTypeID            type = 0;
  23.     OSType                        shape = 0, create = 0;
  24.     DescriptorKeyIDArray        array = { NULLID };
  25.     int32                        flags = 0;
  26.     OSErr                        gotErr = noErr, stickyError = noErr;
  27.     Boolean                        returnValue = true;
  28.     
  29.     if (DescriptorAvailable())
  30.     { /* playing back.  Do our thing. */
  31.         token = OpenReader(array);
  32.         if (token)
  33.         {
  34.             while (PIGetKey(token, &key, &type, &flags))
  35.             {
  36.                 switch (key)
  37.                 {
  38.                     // check keys here
  39.                 }
  40.             }
  41.  
  42.             stickyError = CloseReader(&token); // closes & disposes.
  43.                 
  44.             if (stickyError)
  45.             {
  46.                 if (stickyError == errMissingParameter) // missedParamErr == -1715
  47.                     ;
  48.                     /* (descriptorKeyIDArray != NULL)
  49.                        missing parameter somewhere.  Walk IDarray to find which one. */
  50.                 else
  51.                     gResult = stickyError;
  52.             }
  53.         }
  54.         
  55.         returnValue = PlayDialog();
  56.         /* return TRUE if want to show our Dialog */        
  57.     }
  58.     
  59.     return returnValue;
  60. }
  61.         
  62. /*****************************************************************************/
  63.  
  64. /* Checks the parameters against scripting-returned parameters, if any, and
  65.    updates our parameters to match ones given to us by the scripting system. */
  66.  
  67. Boolean ReadScriptParamsOnWrite (GPtr globals)
  68. {
  69.     PIReadDescriptor            token = NULL;
  70.     DescriptorKeyID                key = 0;
  71.     DescriptorTypeID            type = 0;
  72.     OSType                        shape = 0, create = 0;
  73.     DescriptorKeyIDArray        array = { NULLID };
  74.     int32                        flags = 0;
  75.     OSErr                        gotErr = noErr, stickyError = noErr;
  76.     Boolean                        returnValue = true;
  77.     
  78.     if (DescriptorAvailable())
  79.     { /* playing back.  Do our thing. */
  80.         token = OpenReader(array);
  81.         if (token)
  82.         {
  83.             while (PIGetKey(token, &key, &type, &flags))
  84.             {
  85.                 switch (key)
  86.                 {
  87.                     // check keys here
  88.                 }
  89.             }
  90.  
  91.             stickyError = CloseReader(&token); // closes & disposes.
  92.                 
  93.             if (stickyError)
  94.             {
  95.                 if (stickyError == errMissingParameter) // missedParamErr == -1715
  96.                     ;
  97.                     /* (descriptorKeyIDArray != NULL)
  98.                        missing parameter somewhere.  Walk IDarray to find which one. */
  99.                 else
  100.                     gResult = stickyError;
  101.             }
  102.         }
  103.         
  104.         returnValue = PlayDialog();
  105.         /* return TRUE if want to show our Dialog */        
  106.     }
  107.     
  108.     return returnValue;
  109. }
  110.  
  111. /*****************************************************************************/
  112.  
  113. /* Writes our parameters to the scripting system. */
  114.  
  115. OSErr WriteScriptParamsOnRead (GPtr globals)
  116. {
  117.     PIWriteDescriptor            token = nil;
  118.     OSErr                        gotErr = noErr;
  119.             
  120.     if (DescriptorAvailable())
  121.     { /* recording.  Do our thing. */
  122.         token = OpenWriter();
  123.         if (token)
  124.         {
  125.             // write keys here
  126.             PIPutBool(token, keyFoo, true);
  127.             gotErr = CloseWriter(&token); /* closes and sets dialog optional */
  128.             /* done.  Now pass handle on to Photoshop */
  129.         }
  130.     }
  131.     return gotErr;
  132. }
  133.  
  134.         
  135. /*****************************************************************************/
  136.  
  137. /* Writes our parameters to the scripting system. */
  138.  
  139. OSErr WriteScriptParamsOnWrite (GPtr globals)
  140. {
  141.     PIWriteDescriptor            token = nil;
  142.     OSErr                        gotErr = noErr;
  143.             
  144.     if (DescriptorAvailable())
  145.     { /* recording.  Do our thing. */
  146.         token = OpenWriter();
  147.         if (token)
  148.         {
  149.             // write keys here
  150.             PIPutBool(token, keyBar, true);
  151.             gotErr = CloseWriter(&token); /* closes and sets dialog optional */
  152.             /* done.  Now pass handle on to Photoshop */
  153.         }
  154.     }
  155.     return gotErr;
  156. }